﻿using System;
using System.Globalization;
using System.Windows.Data;
using DataClasses;

namespace CYPlayer.Converter
{
    public class TimeSpanToDoubleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter as string == "string" && !String.IsNullOrEmpty(value as string))
            {
                var current = TimeSpan.Parse(value as string);
                var intSeconds = Song.ConvertSpan(current);
                return System.Convert.ToDouble(intSeconds);
            }
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var doubleSeconds = (double)value;
            var seconds = System.Convert.ToInt32(doubleSeconds);
            return Song.ConvertTotalSeconds(seconds);
        }
    }
}
